package com.gzcstec.rabbitmq.receiver;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * 消息接收
 */
@Component
@Slf4j
public class MqReceiver {

    @RabbitListener(queuesToDeclare = @Queue("amdpQueue"))
    public void receive(String message) {
        log.info("receive:{}" , message);
    }

    @RabbitListener(bindings = @QueueBinding(
                        value = @Queue("fruitOrder"),
                        key = "fruit",
                        exchange = @Exchange("order")
                    ))
    public void fruitReceiver(Message message) {
        log.info("fruitReceiver:{}" , message);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("computerOrder"),
            key = "computer",
            exchange = @Exchange("order")
    ))
    public void receive4Exchange(Message message) {
        log.info("computerReceiver:{}" , message);
    }
}
